import { http } from '@/utils/http'

export interface MixedResourceItem {
  resId: number
  resName: string
  resType: number
  cateId: number
  cateName: string
  tags: string
  resImg: string
  resTime: string
  likeNum: number
  lookNum: number
  commentNum: number
  overTime: string | null
  openCrowd: string
  openCrowdOption: string
  cateImg: string
  isLike: number
  isCollect: number
  content: string
  cateContent: string
  webUrl: string
  isLook: number
  isCompele: number
  cpbProductIntroduction: string
  allowTimes: number
  testTimes: number
  timeLength: number
  optionKey: number
  products: any
  resCover: string
  cateCover: string
  startTime: string | null
  endTime: string | null
  cateNameEn: string
}

export interface MixedResourceParams {
  deptIds?: string
  resType?: string
  // resType 资源类型，null：全部；0：课程；1：产品；2：微课；3：专题；4：活动
  iptr?: string
  cateId?: number
  deptFlag?: number
  page?: number
  limit?: number
}
export interface MixedResourceData {
  totalCount: number
  items: MixedResourceItem[]
}
/* 综合资源列表 */
export function getMixedResourceList({
  deptIds,
  resType,
  iptr,
  cateId,
  deptFlag,
  page = 1,
  limit = 10,
}: MixedResourceParams = {}): Promise<IResData<MixedResourceData>> {
  return http.get<MixedResourceData>('/api/MP/GetMixedResourceList', {
    deptIds,
    resType,
    iptr,
    cateId,
    deptFlag,
    page,
    limit,
  })
}

export interface TopCourseItem {
  allowTimes: number
  cateContent: string
  cateCover: string
  cateId: number
  cateImg: string
  cateName: string
  cateNameEn: string
  commentNum: number
  content: string
  cpbProductIntroduction: string
  endTime: string | null
  isCollect: number
  isCompele: number
  isLike: number
  isLook: number
  likeNum: number
  lookNum: number
  openCrowd: string
  openCrowdOption: string
  optionKey: number
  overTime: string
  products: any
  resCover: string
  resId: number
  resImg: string
  resName: string
  resTime: string
  resType: number
  startTime: string
  tags: string
  testTimes: number
  timeLength: number
  webUrl: string
}

export interface TopCourseData {
  totalCount: number
  items: TopCourseItem[]
}

/* 热门课程列表 */
export function getTopCourseList(limit: number = 4): Promise<IResData<TopCourseData>> {
  return http.get<TopCourseData>('/api/MP/GetTopCourseList', {
    limit,
  })
}
